Ext.define('DCApp.view.attach.DataView', {
    extend: 'Ext.view.View',
    alias: 'widget.attachview',
    requires: [
                 'Ext.data.*',
                 'Ext.util.*',
                 'Ext.view.View',
                 'Ext.ux.DataView.DragSelector',
                 'Ext.ux.DataView.LabelEditor'
             ],   
    tpl: [
          '<tpl for=".">',
              '<div class="thumb-wrap" >',

           '<tpl if="this.isPic(suffix)">',
           		'<div class="thumb" rel="fullScreenGallery" href="{uri}" style="background:url({uri}&size=90) 50% 50% no-repeat;"></div>',
          '<tpl else>',
     			'<a href="{uri}" target="_blank"><div class="thumb-large global-icon-62 global-icon-62-{suffix}"></div></a>',             
          '</tpl>',                    
                  '<span class="x-editable">{name:htmlEncode}</span>',
              '</div>',
          '</tpl>',
          '<div class="x-clear"></div>',{
        	  isPic:function(suffix){
        		  if(suffix=='jpg' || suffix=='png')
        			  return true;
        		  else
        			  return false;
        	  }
          }
      ],
      multiSelect: true,
      cls: 'images-view',
      scrollable: false,
      trackOver: true,
      overItemCls: 'x-item-over',
      itemSelector: 'div.thumb-wrap',
      emptyText: 'No images to display',
      viewModel: {
          type: 'attachlist'
      },
      bind: {
          store: '{objs}'
      },

      plugins: [
          Ext.create('Ext.ux.DataView.DragSelector', {}),
          Ext.create('Ext.ux.DataView.LabelEditor', {dataIndex: 'name'})
      ],
      prepareData1: function(data) {
    	  var uri;
    	  if(data.suffix.indexOf('jpg')!=-1)
    	  	uri= '../imgs/'+data.id % 5+'.jpg'; 
    	  else
    		uri = '../attachs/'+data.name+'.'+data.suffix;
          Ext.apply(data, {
        	  url:uri,
              shortName: Ext.util.Format.ellipsis(data.name, 15),
              sizeString: Ext.util.Format.fileSize(data.filesize),
              dateString: Ext.util.Format.date(data.lastmod, "m/d/Y g:i a")
          });
          return data;
      },
      listeners: {
           selectionchange: function(dv, nodes ){
              var l = nodes.length,
                  s = l !== 1 ? 's' : '';
              this.up('panel').setTitle('附件列表  选中 (' + l + ' 条 )');
          }
      },
      refresh: function() {
    	  this.callParent(arguments);
    	  setTimeout(function(){    		  
    		  var fs =  $('.thumb[rel="fullScreenGallery"]');
    		  if(fs.length==0)
    			  return;
    		  fs.fullScreenGallery();   		  
    	  },200);
      },
    initComponent: function() {        
        this.callParent(arguments);
    }
});